{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5f5de6f1",
   "metadata": {},
   "source": [
    "上机1-01：\n",
    "\n",
    "生成一个由100以内能够被5整除的数组成的列表，然后将该列表的数字从大到小排序。\n",
    "\n",
    "请用3-5种方法（排序方法）完成。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74fcde9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_list = []\n",
    "\n",
    "for i in range(1, 101):\n",
    "    if i % 5 == 0:\n",
    "        my_list.append(i)\n",
    "\n",
    "print(f'Original list:\\t{my_list}')\n",
    "print(f'sorted():\\t{sorted(my_list, reverse=True)}')\n",
    "print(f'reversed():\\t{list(reversed(my_list))}')\n",
    "print(f'Slicing:\\t{my_list[::-1]}')\n",
    "\n",
    "my_list.sort(reverse=True)\n",
    "print(f'sort():\\t{my_list}')\n",
    "\n",
    "# reverse()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9029ba58",
   "metadata": {},
   "source": [
    "Pro✨"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5af1c2d",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_list = [i for i in range(1, 101) if i % 5 == 0]\n",
    "\n",
    "print(f\"{'Original list:':<15}{my_list}\")\n",
    "print(f\"{'sorted():':<15}{sorted(my_list, reverse=True)}\")\n",
    "print(f\"{'reversed():':<15}{list(reversed(my_list))}\")\n",
    "print(f\"{'Slicing:':<15}{my_list[::-1]}\")\n",
    "\n",
    "my_list.sort(reverse=True)\n",
    "print(f\"{'sort():':<15}{my_list}\")\n",
    "\n",
    "my_list.sort()\n",
    "my_list.reverse()\n",
    "print(f\"{'reverse():':<15}{my_list}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67777cee",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de187442",
   "metadata": {},
   "source": [
    "上机1-03：\n",
    "\n",
    "写一段程序，能够实现如下功能：\n",
    "\n",
    "①    输入英文的姓名\n",
    "\n",
    "②    按照字典顺序将所有姓名排序\n",
    "\n",
    "③    输入完毕，将排序结果打印出来\n",
    "\n",
    "提示：\n",
    "\n",
    "```python\n",
    "name_lst = []\n",
    "while True:\n",
    "    name = input(\"Please input an English name(input 'q' then exit)\")\n",
    "    if name == \"q\":\n",
    "        break\n",
    "    else:\n",
    "        name_lst.append(name)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5161c87",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_lst = []\n",
    "while True:\n",
    "    name = input(\"Please input an English name (input 'q' then exit):\")\n",
    "    if name.lower() == \"q\":\n",
    "        break\n",
    "    else:\n",
    "        name_lst.append(name)\n",
    "\n",
    "print(f'Original list: {name_lst}')\n",
    "\n",
    "name_lst.sort()\n",
    "print(f'Sorted list: {name_lst}')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
